#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 16:08
# @Author: 王思淇
# @Email: xxx@gmail.com
# @File：task_page.py

from selenium.webdriver.common.by import By
from config.config import HOST
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select

class TaskPage(BasePage):
    """任务页面类"""
    url = "http://{}/crm/index.php?m=task".format(HOST)
    add_task_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div > a')
    look_locator = (By.LINK_TEXT, "查看")  # 查看任务
    close_locator = (By.LINK_TEXT, "关闭")  # 关闭任务
    xiugai_clue_btn_locator = (By.LINK_TEXT, '修改')

    field_select = (By.XPATH, '//*[@id="field"]')  # 任意字段
    condition_select = (By.NAME, 'condition')  # 包含
    input_medium_locator = (By.CLASS_NAME, 'search-query')  # 输入框
    ss_locator = (By.XPATH, '//*[@id="dosearch"]')  # 搜索
    #统计
    tongji_locator = (By.XPATH, '/html/body/div[5]/div[1]/ul/li[2]/a')

    success_tasck_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[3]/a")


    def click_add_clue(self):
        """点击新建任务"""
        self.driver.find_element(*self.add_task_locator).click()
    def click_look(self):
        """查看"""
        self.driver.find_element(*self.look_locator).click()
    def click_close(self):
        """关闭"""
        self.driver.find_element(*self.close_locator).click()
    def click_change(self):
        """修改"""
        self.driver.find_element(*self.xiugai_clue_btn_locator).click()

    def change_field(self,field):
        """任意字段"""
        select = self.driver.find_element(*self.field_select)
        Select(select).select_by_visible_text(field)

    def condition_task(self,condition):
        select = self.driver.find_element(*self.condition_select)
        Select(select).select_by_visible_text(condition)

    def input_medium(self,medium):
        self.driver.find_element(*self.input_medium_locator).send_keys(medium)
    def seek_task(self):
        self.driver.find_element(*self.ss_locator).click()

    def click_tongji_task(self):
        """统计"""
        self.driver.find_element(*self.tongji_locator).click()

    def success_tasck(self):
        """搜索"""
        success = self.driver.find_element(*self.success_tasck_locator).text
        return success

